﻿#region Usings

using System.IO;
using System.Xml.XPath;

#endregion

namespace Kazkommertsbank.Framework.Model.Pay
{
    public class PaymentSuccessDocument : ResponseDocumentBase
    {
        public PaymentSuccessDocument(string response) : base(response)
        {}

        #region Overrides of DocumentBase

        public override KkbResponseType ResponseType
        {
            get { return KkbResponseType.Success; }
        }

        protected override bool ParseXml(string response)
        {
            try
            {
                XPathDocument doc = new XPathDocument(new StringReader(response));
                XPathNavigator nav = doc.CreateNavigator();
                XPathNavigator navigator = nav.SelectSingleNode("//document/bank");
                if(navigator != null)
                    Bank = new PaymentBank(navigator);

                navigator = nav.SelectSingleNode("//document/bank_sign");
                if(navigator != null)
                {
                    BankSign = navigator.Value;
                    BankSignCertId = navigator.GetAttribute("cert_id", "");
                    BankSignType = navigator.GetAttribute("type", "");
                }

                return true;
            }
            catch
            {
                return false;
            }
        }

        #endregion

        public PaymentBank Bank { get; private set; }
        public string BankSign { get; private set; }
        public string BankSignCertId { get; private set; }
        public string BankSignType { get; private set; }
    }
}